//
//  RHLearningManualVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/30.
//

#import "RHLearningManualVC.h"
#import "RHVideoCell.h"
#import "RHUserManualCell.h"
#import "RHNavigationController.h"
#import "RHContactUsVC.h"

@interface RHLearningManualVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) UITableView *tableView;

@property (nonatomic ,strong) NSArray *dataArr;

@end

@implementation RHLearningManualVC


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"学习手册".rh_localized;
    self.view.backgroundColor = CFTabViewBgColor;
    [self setupUI];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    if([self.navigationController isKindOfClass:[RHNavigationController class]]){
        RHNavigationController *nav = (RHNavigationController*)self.navigationController;
        [nav setBackgoundClear:YES titleColor:nil];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
   
    if([self.navigationController isKindOfClass:[RHNavigationController class]]){
        RHNavigationController *nav = (RHNavigationController*)self.navigationController;
        [nav setBackgoundClear:NO titleColor:nil];
    }
}


-(void)setupUI{
    
    UIImageView *topImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"service_top"]];
    [self.view addSubview:topImg];
    
    [topImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_offset(0);
        make.height.equalTo(topImg.mas_width).multipliedBy(500/700.0);
    }];
    
   
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [_tableView registerClass:[RHVideoCell class] forCellReuseIdentifier:@"RHVideoCell"];
    [_tableView registerClass:[RHUserManualCell class] forCellReuseIdentifier:@"RHUserManualCell"];
    [_tableView setBackgroundColor:UIColor.clearColor];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setSeparatorColor:UIColor.clearColor];
    
    _tableView.tableFooterView = [UIView new];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    _tableView.tableHeaderView = [self headerView];
    
    [self.view addSubview:_tableView];
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = 0;
    }
    

    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.mas_offset(kNavHeight);
        make.bottom.mas_offset(0);
    }];
}



#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 1){
        return 2;
    }
    return 1;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(15, 0, kUI_WINDOW_W-30, 50)];
    headView.layer.cornerRadius = 8;
    headView.layer.masksToBounds = YES;
    headView.layer.maskedCorners = kCALayerMinXMinYCorner|kCALayerMaxXMinYCorner;
    headView.backgroundColor = CFTabViewBgColor;
   
    
    UILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.font = kBOLDSYSTEMFONT(18);
    titleLab.textColor = kColorRGB(0, 0, 0);
    titleLab.textAlignment = NSTextAlignmentLeft;
    titleLab.text = @"使用手册".rh_localized;
    if(section == 1){
        titleLab.text = @"视频教程".rh_localized;
    }
    [headView addSubview:titleLab];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.centerY.mas_offset(0);
     }];

   return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return [UIView new];
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 1){
        RHVideoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHVideoCell"];
        return cell;
    }
    kWeakSelf;
    RHUserManualCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHUserManualCell"];
    cell.clickItemBlock = ^(NSInteger idx) {
        [weakSelf itemAction:idx];
    };
    return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}



-(UIView*)headerView{
 
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, kScaleW(120))];
    headerView.backgroundColor = UIColor.clearColor;
    
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.numberOfLines = 0;
    titleLab.text = @"高效学习让使用更简单".rh_localized;
    titleLab.font = [UIFont systemFontOfSize:14];
    titleLab.textColor = kCOLOR_HEX(@"56C271");
    [headerView addSubview:titleLab];
    
    UIImageView *learnIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"learning_icon"]];
    [headerView addSubview:learnIcon];
  
    [learnIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_offset(0);
        make.right.mas_offset(-15);
        make.width.equalTo(learnIcon.mas_height);
    }];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.equalTo(learnIcon.mas_left).offset(-15);
        make.top.mas_offset(20);
    }];
  
    
    return headerView;
}


-(void)itemAction:(NSInteger)idx
{
    if(idx == 4){
        RHContactUsVC *vc = [[RHContactUsVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}




@end
